package com.kmlitro.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kmlitro.manager.KmLitroMobileManager;

@WebServlet("/KmLitroMobile")
public class KmLitroMobile extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public KmLitroMobile() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String cmd = request.getParameter("cmd");
		
		if (null == cmd) {
			cmd = request.getRequestURI();
		}
		
		KmLitroMobileManager manager = new KmLitroMobileManager(this, request, response);
		
		try {
			manager.execute(cmd);
		} catch (Exception e) {
			System.out.println("[" + com.kmlitro.utils.DateUtils.getCurrentDateHourMinSecFormated()+ "] ### -->" + e.getMessage());
			e.printStackTrace();
			request.setAttribute("errorMsg",e.getMessage());
			getServletConfig().getServletContext().getRequestDispatcher("/mobileerror.jsp").forward(request, response);
		}
		
	}

}
